package com.lesso.zgs.sunflower.domain.service;

import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.zgs.sunflower.domain.repository.AttendanceRuleRepository;
import com.lesso.zgs.sunflower.infra.assembler.AttendanceRuleAssembler;
import com.lesso.zgs.sunflower.model.AttendanceRule;
import com.lesso.zgs.sunflower.pojo.dto.AttendanceRuleDTO;
import com.lesso.zgs.sunflower.pojo.dto.AttendanceRuleQueryDTO;
import com.lesso.zgs.sunflower.pojo.vo.AttendanceRuleVO;
import org.springframework.stereotype.Service;

/**
 * AttendanceRuleDomainService
 *
 * @author zgs
 * @since 2025-07-03
 */
@Service
public class AttendanceRuleDomainService {
    private final AttendanceRuleRepository attendanceRuleRepository;

    public AttendanceRuleDomainService(AttendanceRuleRepository attendanceRuleRepository) {
        this.attendanceRuleRepository = attendanceRuleRepository;
    }

    public Integer save(AttendanceRuleDTO dto) {
        AttendanceRule attendanceRule = AttendanceRuleAssembler.INSTANCE.dtoToEntity(dto);
        return attendanceRuleRepository.save(attendanceRule);
    }

    public AttendanceRuleDTO getById(Long id) {
        AttendanceRule attendanceRule = attendanceRuleRepository.getById(id);
        return AttendanceRuleAssembler.INSTANCE.entityToDto(attendanceRule);
    }

    public Integer update(AttendanceRuleDTO dto) {
        AttendanceRule attendanceRule = AttendanceRuleAssembler.INSTANCE.dtoToEntity(dto);
        return attendanceRuleRepository.update(attendanceRule);
    }

    public Integer delete(Long id) {
        return attendanceRuleRepository.delete(id);
    }

    public Page<AttendanceRuleVO> page(AttendanceRuleQueryDTO dto) {
        return attendanceRuleRepository.getPageList(dto);
    }
} 